home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 10984 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.0 KB

  1. Path: newsbf02.news.aol.com!not-for-mail
  2. From: shinjinrui@aol.com (ShinJinRui)
  3. Newsgroups: comp.lang.c
  4. Subject: Forward Struct Reference
  5. Date: 21 Mar 1996 01:47:21 -0500
  6. Organization: America Online, Inc. (1-800-827-6364)
  7. Sender: root@newsbf02.news.aol.com
  8. Message-ID: <4iqu1p$edq@newsbf02.news.aol.com>
  9. Reply-To: shinjinrui@aol.com (ShinJinRui)
  10.  
  11. What is the best way to declare a typdef for both a struct and a contained
  12. function that operates on it?  I want to have a structure that contains a
  13. pointer to a function that operates on the structure.
  14.  
  15. example:
  16. /* 
  17. *       declare typedef to a function "FuncType" which operates on a
  18. pointer
  19. *       to a struct of type "structType"  (typedef of structType follows
  20. below).
  21. */
  22. typedef void FuncType(*structType);
  23.  
  24. /* 
  25. *        Declare the structure's type 
  26. */
  27. typedef struct structType_tag { 
  28.     int a;
  29.     int b;
  30.     void (*FuncType)(*structType);   
  31. } structType;
  32.  
  33.  
  34. This confuses the compiler, because "structType" is not defined (yet)
  35. where the "funcType" typedef is declared.
  36.  
  37. Any comments or suggestions?  
  38.